#https://www.luogu.com.cn/problem/P1021

def num_with_set(n,posts)
	res=[0]
	rg=(1..n)
	rg.each do |seq|
		temp=[]
		posts.each do |i|
			temp|=res.collect{ |j| i+j }
		end
		res|=temp
	end
	res.sort!
	(0...res.size).each{|i|
		if res[i]!=i
			return i-1
		end
	}
	return res.size-1
end

		

# N 张邮票，计算在给定 K（N+K≤15）种邮票
def prob(n,k)
	if n==1 
		return 1,[1]
	elsif k==1
		return n,[1]
	end
	newnum,oldset = prob(n,k-1);
	oldset<< newnum 
	temp2=num_with_set(n,oldset)
	return temp2 ,oldset
end

num,postset=prob(n=3,k=2)
puts (postset.collect{|i| i.to_s}).join(' ')
puts "MAX=#{num}"